﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using BLL;
using Model;
using Common;

namespace API.Controllers
{
    [RoutePrefix("api/CustomerCom")]
    public class CustomerComController : ApiController
    {
        B_CustomerCom _bcc;
        public CustomerComController()
        {
            _bcc = new B_CustomerCom();
        }

        /// <summary>
        /// 获取所有用户简历的自定义详情：分页
        /// </summary>
        /// <returns></returns>
        [Route("GetAll")]
        [HttpGet]
        public IHttpActionResult GetAll(int page,int size)
        {
            var detail = new B_CustomDetails().GetAll();
            var type = new B_CustomType().GetAll();
            var data = from bc in _bcc.GetAll()
                       join bd in detail on bc.CDetailsID equals bd.CDetailsID
                       join bt in type on bd.CTypeID equals bt.CTypeID
                       select new Param_CustomerCom
                       {
                           ID = bc.ID,
                           CDetailsID = bc.CDetailsID,
                           TemplateID = bc.TemplateID,
                           CTypeID = bd.CTypeID,
                           CName = bt.CName,
                           CDTitle = bd.CDTitle,
                           CTitleGrade = bd.CTitleGrade,
                           CDDescribe = bd.CDDescribe,
                           IsOnTrue = bd.IsOnTrue
                       };
            return Ok(new Result<List<Param_CustomerCom>>()
            {
                Data = data.Skip((page - 1) * size).Take(size).ToList(),
                Msg = data.Count().ToString()
            });
        }

        /// <summary>
        /// 获取所有用户简历的自定义详情
        /// </summary>
        /// <returns></returns>
        [Route("GetAll")]
        [HttpGet]
        public IHttpActionResult GetAll()
        {
            var detail = new B_CustomDetails().GetAll();
            var type = new B_CustomType().GetAll();
            var data = from bc in _bcc.GetAll()
                       join bd in detail on bc.CDetailsID equals bd.CDetailsID
                       join bt in type on bd.CTypeID equals bt.CTypeID
                       select new Param_CustomerCom
                       {
                           ID = bc.ID,
                           CDetailsID = bc.CDetailsID,
                           TemplateID = bc.TemplateID,
                           CTypeID = bd.CTypeID,
                           CName = bt.CName,
                           CDTitle = bd.CDTitle,
                           CTitleGrade = bd.CTitleGrade,
                           CDDescribe = bd.CDDescribe,
                           IsOnTrue = bd.IsOnTrue
                       };
            return Ok(new Result<List<Param_CustomerCom>>() {
                Data=data.ToList()
            });
        }
    }
}
